package com.oa.pm.controller;

import com.joneying.common.web.response.Resp;
import com.oa.core.PageResult;
import com.oa.pm.dto.SchoolRecruitChannelsAddDTO;
import com.oa.pm.dto.SchoolRecruitChannelsListParamDTO;
import com.oa.pm.entity.SchoolRecruitChannels;
import com.oa.pm.service.ISchoolRecruitChannelsService;
import com.oa.pm.vo.SchoolRecruitChannelsDetailsVO;
import com.oa.pm.vo.SchoolRecruitChannelsListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.joneying.common.annotation.CommonController;
import org.springframework.context.annotation.Description;

import java.util.List;

import org.springframework.web.bind.annotation.RestController;
import com.oa.core.BaseController;

/**
 * @author syb123
 * @since 2019-01-22
 */
@RestController
@RequestMapping("/schoolRecruitChannels")
@Api(description = "校招渠道管理表模块")
public class SchoolRecruitChannelsController extends BaseController {

    private final ISchoolRecruitChannelsService schoolRecruitChannelsService;

    @Autowired
    public SchoolRecruitChannelsController(ISchoolRecruitChannelsService schoolRecruitChannelsService) {
        this.schoolRecruitChannelsService = schoolRecruitChannelsService;
    }

    /**
     * 查询列表
     *
     * @return Resp
     */
    @PostMapping("/findList")
    @CommonController
    @Description("查询所有")
    @ApiOperation(value = "查询（不传page则查询所有）")
    public Resp<PageResult<SchoolRecruitChannelsListVO>> findList(SchoolRecruitChannelsListParamDTO schoolRecruitChannelsListParamDTO) {
        return new Resp().success(schoolRecruitChannelsService.findSchoolRecruitChannelsList(schoolRecruitChannelsListParamDTO));
    }

    @GetMapping("/export")
    @CommonController
    @Description("导出")
    @ApiOperation(value = "导出")
    public void export(SchoolRecruitChannelsListParamDTO schoolRecruitChannelsListParamDTO) {
        schoolRecruitChannelsService.export(schoolRecruitChannelsListParamDTO, response);
    }

    /**
     * 根据Id查询
     *
     * @param id id
     * @return Resp
     */
    @PostMapping("/findById")
    @CommonController
    @Description("获取详细信息")
    @ApiOperation(value = "根据id查询")
    public Resp<SchoolRecruitChannelsDetailsVO> findById(@ApiParam(value = "id", required = true) @RequestParam String id) {
        return new Resp().success(schoolRecruitChannelsService.findSchoolRecruitChannelsById(id));
    }


    /**
     * 新增
     *
     * @return Resp
     */
    @PostMapping("/save")
    @CommonController
    @Description("保存")
    @ApiOperation(value = "保存")
    public Resp save(@ApiParam(value = "校招渠道管理表对象") @RequestBody(required = false) SchoolRecruitChannelsAddDTO schoolRecruitChannelsAddDTO) {
        if (schoolRecruitChannelsService.saveSchoolRecruitChannels(schoolRecruitChannelsAddDTO)) {
            return new Resp().success();
        } else {
            return new Resp().failure();
        }
    }

    /**
     * 根据Id删除
     *
     * @param id id
     * @return Resp
     */
    @DeleteMapping("/{id}")
    @CommonController
    @Description("根据id删除")
    @ApiOperation(value = "根据id删除")
    public Resp delete(@ApiParam(value = "id", required = true) @PathVariable("id") String id) {
        SchoolRecruitChannels schoolRecruitChannels = schoolRecruitChannelsService.selectById(id);
        if (schoolRecruitChannels != null && schoolRecruitChannels.getIsDeleted() == 2) {
            schoolRecruitChannels.setIsDeleted(1);
            if (schoolRecruitChannelsService.updateById(schoolRecruitChannels)) {
                return new Resp().success();
            }
            return new Resp().failure();
        }
        return new Resp().failure();
    }
}
